package com.toy.core.security.userdetails;

import org.apache.commons.lang.StringUtils;

import com.toy.core.security.exception.AuthenticationException;

public class UserDetailsServiceInMemory implements UserDetailsService {

	public UserDetail getByUsername(String username)
			throws AuthenticationException {
		if (StringUtils.isBlank(username)){
			throw new AuthenticationException(AuthenticationException.CODE_UsernameNotFoundException);
		}
		return new UserDetailsImpl(username,null,false,false,false,false,null);
	}

	public UserDetail validate(String username, String password)
			throws AuthenticationException {
		if (StringUtils.isBlank(username)){
			throw new AuthenticationException(AuthenticationException.CODE_UsernameNotFoundException);
		}
		if (StringUtils.isBlank(password)){
			throw new AuthenticationException(AuthenticationException.CODE_BadCredentialsException);
		}
		if (!username.equalsIgnoreCase(password)){
			throw new AuthenticationException(AuthenticationException.CODE_BadCredentialsException);
		}
		return new UserDetailsImpl(username,password,false,false,false,false,null);
	}

}
